import sqlite3
import os

class Database:
    def __init__(self):
        self.databaseLocation = os.environ.get("HOME") + "/.pyday"
    
    def database_exists(self):
        if os.path.exists(os.environ.get("HOME") + "/.pyday") == 1:
            return True
        else:
            return False
        
    def create_database(self):
        if self.ask_to_create_database():
            conn = sqlite3.connect(self.databaseLocation)
            c = conn.cursor()
            c.execute('''create table events
                      (event_name text, event_type integer, 
                       start_date text, end_date text)''')
        else:
            return False
    
    def ask_to_create_database(self):
        print "Database does not exist, create a new one(y,N)?:"
        create = raw_input()
        
        if create == '':
            return False
        
        create = create.lower()[0]
        
        if create == 'n':
            return False
        elif create == 'y':
            return True
        else:
            print 'Invalid entry'
            self.ask_to_create_database()

